<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<%@page import="com.framework.utils.ConfigUtil"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jqGird</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <style>
        .ml10 {
            margin-left: 15px;
        }

    </style>

</head>

<body class="gray-bg" >
<div class="wrapper wrapper-content  animated fadeInRight" id="ccbb">
    <div class="row">
        <div class="col-sm-12">
            <div class="toolbar">
                <div id="toolbar">
                    <shiro:hasPermission name="merchant:add">
                        <button id="btn_add" class="btn btn-primary"><i class="fa fa-plus-circle"></i>&nbsp;新增</button>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="merchant:del" >
                        <button id="btn_del" class="btn btn-w-s btn-danger"><i class="fa fa-times-circle"></i>&nbsp;批量删除</button>
                    </shiro:hasPermission>
                </div>
            </div>


            <span id="spancc" class="spancc"></span>
            <div class="row">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>搜索条件</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content" >
                        <div class="row">
                            <div class="col-md-2"><input placeholder="客户" id="search_customer" class="form-control" id="search_customer"></div>
                            <div class="col-md-1"><button id="btn_search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</button></div>
                        </div>
                    </div>
                </div>
            </div>
            <table id="merchantTablePagin"></table>
        </div>
    </div>
    </div>
</body>
    <script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/bootstrap-table.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/locale/bootstrap-table-zh-CN.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/export/bootstrap-table-export.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/bootstrap-table-master/extensions/editable/bootstrap-table-editable.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/layer/laydate/laydate.js"></script>
    <script>

    </script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <script type="text/javascript">
        var picPath='<%=ConfigUtil.get("OSSURL")%>';
        //初始化表格对象
        var $table = $('#merchantTablePagin');
        /*
         获取选中行的相关数据
         */
        $(function () {
            $table.on('click-row.bs.table', function (e, row, $element) {
                $('.success').removeClass('success');
                $($element).addClass('success');
            });

        });
        function getSelectedRow() {
            var index = $table.find('tr.success').data('index');
            return $table.bootstrapTable('getData')[index];
        }

        /*
         操作按钮的初始化
         */
        function userOperation(value, row, index) {
            return [
                '<a class="edit ml10" href="javascript:void(0)" title="编辑">',
                '<i class="glyphicon glyphicon-edit"></i>',
                '</a>',

                '<a class="remove ml10" href="javascript:void(0)" title="删除">',
                '<i class="glyphicon glyphicon-remove"></i>',
                '</a>'
            ].join('');
        }
        //每个按钮对应的事件
        window.actionEvents = {
            'click .edit': function (e, value, row, index) {
                //弹出编辑层
                showPopup();
            },
            'click .remove': function (e, value, row, index) {
                alert('You click remove icon,: ' + JSON.stringify(row));

            }
        };

        /*
         每一列详情格式化数据
         */
        function formDetail(index, row) {
            return row.customer+index;
        }

        function showPopupForEdit(id){
            //自定页
            parent.layer.open({
                type: 2,
                shift:4,//动画类型
                moveType:1,
                maxmin: true,
                shadeClose: true, //开启遮罩关闭
                area: ['800px', '600px'],
                content: '${pageContext.request.contextPath}/merchant/toEdit.ac?id='+id,
                success: function(layero, index){

                },
                cancel: function(index){
                    $table.bootstrapTable('refresh', queryParams);
                    return true;
                },
                close  : function(index){
                    $table.bootstrapTable('refresh', queryParams);
                }
            });
        }
        function showPopup(id){
            //自定页
            parent.layer.open({
                type: 2,
                shift:4,//动画类型
                moveType:1,
                maxmin: true,
                shadeClose: true, //开启遮罩关闭
                area: ['800px', '530px'],
                content: '${pageContext.request.contextPath}/jsp/basic/form_edit.jsp?id='+id+'&cityId='+${cityId},
                success: function(layero, index){
                    //layer.title("888888888", index);
                    var datas={"firstname":"555555"};
                    var body = layer.getChildFrame('body', index);
                    //var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    //console.log(body.html()) //得到iframe页的body内容
                },
                cancel: function(index){
                    return true;
                }
            });
        }

        ////////////////////////////////////////////////////////////////////////////////////////以下是通过js方式初始化BootStrapTable/////////////////////////////////////////////

        $table.bootstrapTable({
            url: "${pageContext.request.contextPath}/merchant/showMerchant.ac",
            method: 'post',
            contentType: "application/x-www-form-urlencoded",//必须的
            dataType: "json",
            pageList:[10, 20, 50, 100],//会根据当前的数据量加载合适的pageList
            height: ($(window).height()-100) ,
            //cardView:true,//是否自适应手机
            pagination: true, //分页
            // queryParamsType: "limit",
            singleSelect: false,
            cache:false,
            sortName:"name",
            search: false, //显示搜索框
            showColumns:false,
            showRefresh:false,
            showToggle:false,
           showPaginationSwitch:false,
            smartDisplay:true,
            detailView:true,
            toolbar:"#toolbar",
            queryParams: queryParams,//参数
            searchOnEnterKey:true,
            detailFormatter:function(index, row, element){
                return row.name;
            },
            sidePagination: "server", //服务端处理分页
            columns: [
                {
                    visible:false,
                    field:'brand_code'
                },
                {
                    title:'选择',
                    formatter:stateFormatter2,
                    align:'center',
                    checkbox:true
                },
                {
                    title: '商户LOGO',
                    formatter:function (value, row, index) {
                        if(row.logo_url!=null&&row.logo_url!=undefined&&row.logo_url!='')
                        { return '<image style="width:40px;height: 40px;" src="'+picPath+row.logo_url+'"  />';}
                        else
                        { return '<image src="${ctxStatic}/plugins/nic/assets/admin/layout/img/logo.png"  />';}

                    },
                    align: 'center'
                },
                {
                    title: '商户名称',
                    field: 'name',
                    titleTooltip: '点击可以进行排序操作',
                    sortStable:true,
                    align: 'center'
                },
                {
                    title: '所属行业',
                    formatter:function (value, row, index) {
                        var fn=row.category_first_name;
                        var fs=row.category_second_name;
                        if(row.category_first_name==undefined||row.category_first_name==null)
                        {fn=' ';}
                        if(row.category_second_name==undefined||row.category_second_name==null)
                        {fs=' ';}
                        var temp=fn+" "+fs;
                        return "<span>"+temp+"</span>";
                    },
                    align: 'center'
                },
                {
                    title: '锁定',
                    events:{
                        'change .switch': function (e, value, row, index) {
                            btn_lock(row.brand_code);
                        }
                    },
                    formatter:function (value, row, index) {
                        var locktemp='';
                        lockId="lock"+row.brand_code;
                        row.islock==0?locktemp='<input type="checkbox"  class="onoffswitch-checkbox" id="'+lockId+'">':
                        locktemp='<input  type="checkbox" checked  class="onoffswitch-checkbox" id="'+lockId+'">';
                        var temp='<div  class="switch">'+
                                '<div class="onoffswitch">'+locktemp+
                                '<label class="onoffswitch-label" for="'+lockId+'">'+
                                '<span class="onoffswitch-inner"></span>'+
                                '<span class="onoffswitch-switch"></span>'+
                                '</label>'+
                                '</div>'+
                                '</div>';
                        return temp;
                    },
                    align: 'center'
                },
                {
                    title: '新增用户数',
                    field: 'salesUserCount',
                    align: 'center'
                },
                {
                    title: '创建时间',
                    field: 'create_time',
                    align: 'center'
                },
                {
                    title: '操作',
                    align: 'center',
                    events:{
                        'click .edit': function (e, value, row, index) {
                            //弹出编辑层
                            showPopupForEdit(row.brand_code);
                        },
                        'click .reset': function (e, value, row, index) {
                            //弹出编辑层
                            resetPwd(row.brand_code);
                        },
                        'click .remove': function (e, value, row, index) {
                            var arr=[row.brand_code];
                            deleteGrid(arr);
                        }
                    },
                    formatter:function(value,row,index){
                        return [
                            <shiro:hasPermission name="merchant:update" >
                            '<a class="reset ml10" href="javascript:void(0)" title="重置密码">',
                            '重置密码',
                            '</a>',
                            '<a class="edit ml10" href="javascript:void(0)" title="编辑">',
                            '<i class="glyphicon glyphicon-edit"></i>',
                            '</a>',
                            </shiro:hasPermission>
                            <shiro:hasPermission name="merchant:del" >
                            '<a class="remove ml10" href="javascript:void(0)" title="删除">',
                            '<i class="glyphicon glyphicon-remove"></i>',
                            '</a>'
                            </shiro:hasPermission>
                        ].join('');
                    }
                }
            ]
        });

        /*
         搜索按钮
         */
        $("#btn_search").click(function(){
            $table.bootstrapTable('selectPage', 1);
            $table.bootstrapTable('refresh', queryParams);
        });

        /*
         传递的参数
         */
        function queryParams(params) {
            var name=$("#search_customer").val();
            var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                limit: params.limit,  //页面大小
                offset: params.offset, //页码
                pageindex:params.pageNumber,
                name: name
            };
            return temp;
        }
        ///////////////////////////////////////////////////////////////toolbar///////////////////////////////////////
        //新增
        $("#btn_add").click(function(){
            showPopup();
        });

        //批量删除
        $("#btn_del").click(function(){
            var ids=getSelections();
            //执行批量删除
            deleteGrid(ids);
        });


        //锁定状态

        function btn_lock(id) {
            swal({
                title: "您确定要更改商户锁定状态吗",
                text: "商户锁定状态改变！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText:"取消",
                closeOnConfirm: false
            }, function (isConfirm) {
                if(isConfirm){
                    $.ajax( {
                        url:'${pageContext.request.contextPath}/merchant/changeStateById.ac',
                        data:{
                            ids :id
                        },
                        type:'post',
                        cache:false,
                        dataType:'json',
                        success:function(data) {
                            if(data.success){
                                swal("状态更改成功！", "您已经更改了这条信息。", "success");
                                //当前表格刷新
                                $table.bootstrapTable('refresh');
                            }else{
                                swal("更改失败！", "未能更改这些信息。", "error");
                            }
                        },
                        error : function() {
                            alert("异常！");
                        }
                    });
                }else{
                    $table.bootstrapTable('refresh');
                }

            });

        }

        //重置密码
        function resetPwd(id)
        {
            swal({
                title: "您确定要重置商户密码吗？",
                text: "重置商户密码！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText:"取消",
                closeOnConfirm: false
            }, function (isConfirm) {
                if(isConfirm){
                    $.ajax( {
                        url:'${pageContext.request.contextPath}/merchant/resetPwdById.ac',
                        data:{
                            ids :id
                        },
                        type:'post',
                        cache:false,
                        dataType:'json',
                        success:function(data) {
                            if(data.success){
                                swal("密码重置成功！", "密码已更改为:123456。", "success");
                                //当前表格刷新
                                $table.bootstrapTable('refresh');
                            }else{
                                swal("重置失败！", "未能更改这些信息。", "error");
                            }
                        },
                        error : function() {
                            alert("异常！");
                        }
                    });
                }else{
                    $table.bootstrapTable('refresh');
                }

            });
        }
        /*
         批量删除方法体
         */
        function deleteGrid(ids){
            if(ids.length>0){
                swal({
                    title: "您确定要删除这些信息吗",
                    text: "删除后将无法恢复，请谨慎操作！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "删除",
                    cancelButtonText:"取消",
                    closeOnConfirm: false
                }, function () {
                    //执行批量删除
                    $.ajax( {
                        url:'${pageContext.request.contextPath}/merchant/delGridById.ac',// 跳转到 action
                        data:{
                            ids :ids.toString()
                        },
                        type:'post',
                        cache:false,
                        dataType:'json',
                        success:function(data) {
                            if(data.success){
                                swal("删除成功！", "您已经删除了这条信息。", "success");
                                //当前表格刷新
                                $table.bootstrapTable('refresh');
                            }else{
                                swal("删除失败！", "未能删除这些信息。", "error");
                            }
                        },
                        error : function() {
                            alert("异常！");
                        }
                    });
                });
            }else{
                sweetAlert("无法操作！", "请勾选需要删除的信息!", "error");
            }
        }



        /*
         获取所有选中的CheckBox的主键值 【数组】
         */
        function getSelections() {
            return $.map($table.bootstrapTable('getSelections'), function (row) {
                return row.brand_code;
            });
        }

        /*
         BootStrapTable CheckBox 状态初始化
         */
        function stateFormatter2(value, row, index) {
            if (row.id === 2) {
                return {
                    disabled: true,
                    checked: true
                };
            }
            if (row.id === 0) {
                return {
                    disabled: true,
                    checked: true
                }
            }
            return value;
        }


    </script>



</html>
